﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyDMS.BusinessLayer;

public partial class admin_Department : PageBaseClass
{
    DepartmentFactory dFactory;
    protected void Page_Load(object sender, EventArgs e)
    {
        dFactory = new DepartmentFactory();
        List<Department> departments = dFactory.GetAllBy(Department.DepartmentFields.Office_Code, _author.office_Code);
        this.gvDept.DataSource = departments;
        this.gvDept.DataBind();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Department dept = new Department();
        dept.Department_Name = txtDeptName.Text;
        dept.Location = txtLocation.Text;
        dept.Address = txtAddress.Text;
        dept.Office_Code = _author.office_Code;

        DepartmentFactory dFactory = new DepartmentFactory();
        if (dFactory.Insert(dept))
        {
            lblMessage.Text = "Saved Successfully";
        }
        else
        {
            lblMessage.Text = "Error!";
        }
        lblMessage.Visible = true;
    }
}
